package com.example.constellation.Activity;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.constellation.R;
import com.example.constellation.bean.JsBean;
import com.example.constellation.utils.AssetsUtils;
import com.example.constellation.utils.LoadData;
import com.example.constellation.utils.URLcontent;
import com.google.gson.Gson;

import org.w3c.dom.Text;

import java.util.Map;

import de.hdodenhof.circleimageview.CircleImageView;

public class fg2pdActivity extends AppCompatActivity implements LoadData.ongetnetdata{
    private TextView pdtxtman,pdtxtwoman,pdtxt1,pdtxt2,pdtxt3,pdtxt4,pdtxt5,pdtxt6,titletv;
    private CircleImageView pdimgman,pdimgwoman;
    private ImageView back;
    private String man_name;
    private String man_logoname;
    private String woman_name;
    private String woman_logoname;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_fg2pd);
        initview();
        //接收数值
        getLastdata();
        //获取网络路径地址
        String url = URLcontent.getURL(man_name, woman_name);
        //加载网络数据
        //创造自定义异步任务对象
        LoadData loadData = new LoadData(this, this, true);
        //执行异步任务
        loadData.execute(url);
        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }

    @Override
    public void onsucess(String json) {
        //解析数据
        if (!TextUtils.isEmpty(json)) {
            JsBean jsBean = new Gson().fromJson(json,JsBean.class);
            JsBean.ResultBean result =jsBean.getResult();
            pdtxt3.setText("配对评分:"+result.getZhishu()+" "+result.getJieguo());
            pdtxt4.setText("星座比重:"+result.getBizhong());
            pdtxt5.setText("解析:\n\n"+result.getLianai());
            pdtxt6.setText("注意事项:\n\n"+result.getZhuyi());
        }
    }

    private void getLastdata() {
        Intent intent = getIntent();
        man_name = intent.getStringExtra("man_name");
        man_logoname = intent.getStringExtra("man_logoname");
        woman_name = intent.getStringExtra("woman_name");
        woman_logoname = intent.getStringExtra("woman_logoname");
        Map<String, Bitmap> contentlogomap = AssetsUtils.getContentlogomap();
        Bitmap manbitmap = contentlogomap.get(man_logoname);
        pdimgman.setImageBitmap(manbitmap);
        Bitmap womanbitmap = contentlogomap.get(woman_logoname);
        pdimgwoman.setImageBitmap(womanbitmap);
        pdtxtman.setText(man_name);
        pdtxtwoman.setText(woman_name);
        pdtxt1.setText("星座配对-"+man_name+"和"+woman_name+"配对");
        pdtxt2.setText(man_name+"vs"+woman_name);

    }

    private void initview() {
        pdtxtman=findViewById(R.id.pdtxtman);
        pdtxtwoman=findViewById(R.id.pdtxtwoman);
        pdtxt1=findViewById(R.id.pdtxt1);
        pdtxt2=findViewById(R.id.pdtxt2);
        pdtxt3=findViewById(R.id.pdtxt3);
        pdtxt4=findViewById(R.id.pdtxt4);
        pdtxt5=findViewById(R.id.pdtxt5);
        pdtxt6=findViewById(R.id.pdtxt6);
        titletv=findViewById(R.id.title);
        back=findViewById(R.id.title_back);
        pdimgman=findViewById(R.id.pdimgman);
        pdimgwoman=findViewById(R.id.pdimgwoman);
        titletv.setText("配对详情");
    }


}
